import { baseUrl, billBaseUrl } from "@/utils/config.js"
import { random_string } from '@/utils/common.js';
const placeholderStyle = 'color:#ccc;font-size:28rpx;font-weight: bold;'
const displayStyle = 'display: flex;align-items: center;justify-content: center;'
const inputStyle = {
  fontSize: '28rpx',
  textAlign: 'right',
  fontWeight: 'bold'
}
const rightStyle = 'width: 44rpx;height: 70rpx;display: flex;justify-content: flex-end;align-items: center;'
const hotelModel = {
  title: '住宿专用票据',
  type: 'hotel',
  rules: {
    customerName: [{
      required: true,
      message: '请填写客户姓名',
      trigger: ['change', 'blur']
    }],
    receivableAmount: [{
      required: true,
      message: '请填写应收金额',
      trigger: ['change', 'blur']
    }]
  },
  data: [[
    {
      key: 'copy',
      type: 'copy',
      placeholder: '粘贴信息，自动拆分客户名称、电话和地址',
      style: 'min-height: 140rpx;',
    }
  ],
  [
    {
      key: 'customerName',
      type: 'input',
      inputType: 'text',
      label: '客户名称',
      placeholder: '填写客户名称',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: true,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: {
        style: rightStyle,
        img: billBaseUrl + 'tiaozhuantongxunlu@3x.png',
        label: '',
        imageViewStyle: displayStyle + 'width: 32rpx;height:32rpx;flex-shrink: 0;',
        func: 'chooseMember'
      },
    },
    {
      key: 'customerPhone',
      type: 'input',
      inputType: 'number',
      label: '联系电话',
      placeholder: '请填写客户联系方式',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: null,
    }, {
      key: 'address',
      type: 'input',
      inputType: 'text',
      label: '家庭地址',
      placeholder: '选择地址',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      height: 70,
      clearable: false,
      borderBottom: true,
      right: {
        style: rightStyle,
        img: baseUrl + 'didian@3x.png',
        label: '',
        imageViewStyle: displayStyle + 'width: 28rpx;height:32rpx;flex-shrink: 0;',
        func: 'getAddress'
      },
    }, {
      key: 'idNumber',
      type: 'input',
      inputType: 'idcard',
      label: '身份证号',
      placeholder: '请填写身份证号',
      customStyle: inputStyle,
      placeholderStyle: placeholderStyle,
      required: false,
      height: 70,
      clearable: false,
      borderBottom: false,
      right: null,
    }
  ], [
    {
      key: 'expenseDetails',
      type: 'form',
      label: '收据明细',
    }
  ], [
    {
      type: 'money',
      placeholderStyle: 'color:#ccc;font-size:28rpx;font-weight: bold;',
      customStyle: {
        fontSize: '28rpx',
        textAlign: 'right',
        fontWeight: 'bold'
      },
      labels: {
        expenseDetails: '收据明细',
        receivableAmount: '应收金额',
        actualAmount: '实收金额',
        resultAmount: '欠款金额',
        repairTime: '服务时间'
      }
    }
  ], [
    {
      key: 'extend',
      subKey: 'indicateInfo',
      type: 'textarea',
      inputType: 'indicate-remark',
      label: '注明信息',
      placeholder: '请填写注明信息',
      style: 'min-height: 240rpx;',
      func: 'editRemark',
      right: {
        label: '选模板',
        func: 'chooseRemark'
      }
    }
  ], [
    {
      key: 'remark',
      type: 'textarea',
      inputType: 'maintain-remark',
      label: '备注信息',
      placeholder: '入住时间：2023年10月10日晚上8点；房间要求：无烟房，高楼层（10楼以上）。',
      style: 'min-height: 240rpx;',
      func: 'editRemark',
	  right: {
	    label: '选模板',
	    func: 'chooseRemark'
	  }
    },
  ], [
    {
      key: 'extend',
      subKey: 'customerSignSwitch',
      type: 'switch',
      label: '是否需要客户签字',
      func: 'handleChangeShowSign',
    }
  ], [
    {
      key: 'extend',
      type: 'seal',
    }
  ]],
  sealInfos: [
    {
      label: "水印",
      selectText: '选择电子水印',
      url: '',
      selected: true,
      value: '1',
      code: 'ELECTRON',
      width: 202
    },
    {
      label: "公章",
      selectText: '选择公章',
      url: '',
      selected: false,
      value: '2',
      code: 'OFFICIAL',
      width: 202
    },
    {
      label: "不使用",
      url: '',
      selected: false,
      value: '3',
      code: '',
      width: 202
    }
  ],
  initFormFunc: (form) => {
    form.timeInfo.houseDateRange = [uni.$u.timeFormat(new Date().getTime(), 'yyyy-mm-dd'), '']
    form.actualAmount = 0
    form.expenseDetails = [
      { key: 'number', name: '房号', value: '', uid: random_string() },
      { key: 'daterange', name: '住宿起止日期', value: form.timeInfo.houseDateRange, uid: random_string(), require: true },
      { key: 'price', name: '房价(当日)', value: '', uid: random_string(), require: true },
      { key: 'deposit', name: '押金', value: '', uid: random_string() }
    ]
    form.extend.indicateInfo = '1.中午十二点前退房退押金，开单后不办退房手续;\n2.超出十二点加收半天房价，超出下午六点收全天房价;\n3.房间不得随便带人留宿，或转租他人，不得损坏本房财产，否则照价赔偿;\n4.贵重物品各自随身保管，丢失被盗房主不负其责。'
  },
  changeFormFunc: (val)=> {
    let form = JSON.parse(JSON.stringify(val))
    form.repairTime = form.timeInfo.day + ' ' + form.timeInfo.time
    return form
  },
  setFormFunc: (form)=> {
    for (var item of form.expenseDetails) {
      if (item.key == 'daterange') {
        form.timeInfo.houseDateRange = item.value
        break
      }
    }
  }
}

export default hotelModel